package com.demo.controller;

import com.demo.service.CourseService;
import com.demo.util.Result;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;

@RestController
@Api
public class CourseController {

    @Autowired
    CourseService courseService;

    @ApiOperation("根据学期获得班级课程")
    @RequestMapping("/getClassByTerm")
    public Result getClassByTerm(String term){
        Result result = new Result();
        result.setCode(1);
        result.setMessage("success");
        result.setHeaders(null);
        List<HashMap<String,String>> data = new ArrayList<>();
        List<String> courses =  courseService.findAllCourseByTerm(term);
        for (String i: courses
             ) {
            HashMap<String,String> temp = new HashMap<>();
            temp.put("id",String.valueOf(courseService.getCidByName(i)));
            temp.put("name",i);
            data.add(temp);
        }
        result.setData(data);
        return result;
    }


}
